<template>
  <div :class="{'searchBar': true, 'searchBarFocus': inputFocus}">
    <input
      v-model="inputSearch"
      placeholder="请输入要查找的内容"
      class="searchInput"
      @focus="inputOn"
      @blur="inputOff"
    >
    <div class="searchIcon" @click="searchHandle">
      <el-icon :size="22"><Search /></el-icon>
    </div>
  </div>

  <searchList v-if="openPromotion"
              v-model:openPromotion="openPromotion"
              :param="param"
  />

</template>

<script setup lang="ts">
import { ref, defineModel } from 'vue'
import { Search } from '@element-plus/icons-vue'
import searchList from "@/components/activity/search/searchList.vue";

const openPromotion = defineModel('openPromotion')
const inputSearch = ref('')
const selects = ref('')
const select = ref([
  {
    name: '测试1',
    value: 1
  },
  {
    name: '测试2',
    value: 2
  },
  {
    name: '测试3',
    value: 3
  },
])
const inputFocus = ref(false)
const param = ref({})

function inputOn(){
    inputFocus.value = true
}
function inputOff(){
    inputFocus.value = false
}

const searchHandle = () => {
  param.value = {
    keyword: inputSearch
  }
  openPromotion.value = true
}

</script>

<style scoped>
.searchBar{
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(225, 225, 225, 0.35);
  width: 350px;
  height: 43px;
  border-radius: 10px;
  transition: all 0.3s ease-in-out;
  font-size: 20px;
}
.searchBar:hover{
  background-color: rgb(225, 225, 225, 0.9);
}
.searchBarFocus{
  background-color: rgb(225, 225, 225, 0.9);
}

.searchInput{
  height: 90%;
  width: 85%;
  border: none;
  outline: none;
  background-color: transparent;
}
.searchInput:checked{
  border: 0;
}

.searchIcon{
  position: relative;
  top:2.5px;
  cursor: pointer;
}
</style>
